﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace IISLogAnalyzer.Common
{
    public class Statics
    {

        /// <summary>
        /// 获取显示列Sql
        /// </summary>
        /// <returns></returns>
        public static string GetSqlColumns()
        {
            string sql = "";
            sql += _date == 1 ? "[_date] as 日期," : "";
            sql += _time == 1 ? "[_time] as 时间," : "";
            sql += _ssitename == 1 ? "[_s_sitename] as 服务名称," : "";
            sql += _scomputername == 1 ? "[_s_computername] as 服务器名称," : "";
            sql += _sip == 1 ? "[_s_ip] as 服务器IP," : "";
            sql += _cshost == 1 ? "[_cs_host] as 主机," : "";
            sql += _csmethod == 1 ? "[_cs_method] as 方法," : "";
            sql += _csuristem == 1 ? "[_cs_uri_stem] as URI资源," : "";
            sql += _csuriquery == 1 ? "[_cs_uri_query] as URI查询," : "";
            sql += _sport == 1 ? "[_s_port] as 服务器端口号," : "";
            sql += _csusername == 1 ? "[_cs_username] as 用户名," : "";
            sql += _cip == 1 ? "[_c_ip] as 客户端IP," : "";
            sql += _csversion == 1 ? "[_cs_version] as 协议版本," : "";
            sql += _csuseragent == 1 ? "[_cs_user_agent] as 用户代理," : "";
            sql += _csreferer == 1 ? "[_cs_referer] as 引用网站," : "";
            sql += _scstatus == 1 ? "[_sc_status] as 协议状态," : "";
            sql += _scsubstatus == 1 ? "[_sc_substatus] as 协议子状态," : "";
            sql += _scwin32status == 1 ? "[_sc_win32_status] as Win32状态," : "";
            sql += _scbytes == 1 ? "[_sc_bytes] as 发送字节数," : "";
            sql += _csbytes == 1 ? "[_cs_bytes] as 接收字节数," : "";
            sql += _timetaken == 1 ? "[_time_taken] as [耗时（ms）]," : "";
            sql += _cscookie == 1 ? "[_cs_cookie] as Cookie," : "";
            sql += _add_time == 1 ? "[_add_time] as 分析时间" : "";
            return sql;
        }

        /// <summary>
        /// 获取显示列Sql
        /// </summary>
        /// <returns></returns>
        public static string GetLikeSqlColumns(string key)
        {
            string sql = "";
            sql += _date == 1 ? "[_date] like '%" + key + "%' or " : "";
            sql += _time == 1 ? "[_time] like '%" + key + "%' or " : "";
            sql += _ssitename == 1 ? "[_s_sitename] like '%" + key + "%' or " : "";
            sql += _scomputername == 1 ? "[_s_computername] like '%" + key + "%' or " : "";
            sql += _sip == 1 ? "[_s_ip] like '%" + key + "%' or " : "";
            sql += _cshost == 1 ? "[_cs_host] like '%" + key + "%' or " : "";
            sql += _csmethod == 1 ? "[_cs_method] like '%" + key + "%' or " : "";
            sql += _csuristem == 1 ? "[_cs_uri_stem] like '%" + key + "%' or " : "";
            sql += _csuriquery == 1 ? "[_cs_uri_query] like '%" + key + "%' or " : "";
            sql += _sport == 1 ? "[_s_port] like '%" + key + "%' or " : "";
            sql += _csusername == 1 ? "[_cs_username] like '%" + key + "%' or " : "";
            sql += _cip == 1 ? "[_c_ip] like '%" + key + "%' or " : "";
            sql += _csversion == 1 ? "[_cs_version] like '%" + key + "%' or " : "";
            sql += _csuseragent == 1 ? "[_cs_user_agent] like '%" + key + "%' or " : "";
            sql += _csreferer == 1 ? "[_cs_referer] like '%" + key + "%' or " : "";
            sql += _scstatus == 1 ? "[_sc_status] like '%" + key + "%' or " : "";
            sql += _scsubstatus == 1 ? "[_sc_substatus] like '%" + key + "%' or " : "";
            sql += _scwin32status == 1 ? "[_sc_win32_status] like '%" + key + "%' or " : "";
            sql += _scbytes == 1 ? "[_sc_bytes] like '%" + key + "%' or " : "";
            sql += _csbytes == 1 ? "[_cs_bytes] like '%" + key + "%' or " : "";
            sql += _timetaken == 1 ? "[_time_taken] like '%" + key + "%' or " : "";
            sql += _cscookie == 1 ? "[_cs_cookie] like '%" + key + "%' or " : "";
            sql += _add_time == 1 ? "[_add_time] like '%" + key + "%' " : "";
            return sql;
        }

        public string columsSql { get; set; } = "[_date] as 日期,[_time] as 时间,[_s_sitename] as 服务名称,[_s_computername] as 服务器名称,[_s_ip] as 服务器IP,[_cs_host] as 主机,[_cs_method] as 方法,[_cs_uri_stem] as URI资源,[_cs_uri_query] as URI查询,[_s_port] as 服务器端口号,[_cs_username] as 用户名,[_c_ip] as 客户端IP,[_cs_version] as 协议版本,[_cs_user_agent] as 用户代理,[_cs_referer] as 引用网站,[_sc_status] as 协议状态,[_sc_substatus] as 协议子状态,[_sc_win32_status] as Win32状态,[_sc_bytes] as 发送字节数,[_cs_bytes] as 接收字节数,[_time_taken] as [耗时（ms）],[_cs_cookie] as Cookie,[_add_time] as 分析时间";

        public string SqlLikeColumns { get; set; } = "[_date] like @_date ,[_time] like @_time,[_s_sitename] like @_time,[_s_computername] like @_time,[_s_ip] like @_time,[_cs_host] like @_time,[_cs_method] like @_time,[_cs_uri_stem] like @_time,[_cs_uri_query] like @_time,[_s_port] like @_time,[_cs_username] like @_time,[_c_ip] like @_time,[_cs_version] like @_time,[_cs_user_agent] like @_time,[_cs_referer] like @_time,[_sc_status] like @_time,[_sc_substatus] like @_time,[_sc_win32_status] like @_time,[_sc_bytes] like @_time,[_cs_bytes]  like @_time,[_time_taken] like @_time,[_cs_cookie] like @_time,[_add_time] like @_time";


        /// <summary>
        /// 日期
        /// </summary>
        public static int _date { get; set; } = 1;
        /// <summary>
        /// 时间
        /// </summary>
        public static int _time { get; set; } = 1;
        /// <summary>
        /// 服务名称
        /// </summary>
        public static int _ssitename { get; set; } = 1;
        /// <summary>
        /// 服务器名称
        /// </summary>
        public static int _scomputername { get; set; } = 1;
        /// <summary>
        /// 服务器IP
        /// </summary>
        public static int _sip { get; set; } = 1;
        /// <summary>
        /// 方法
        /// </summary>
        public static int _csmethod { get; set; } = 1;
        /// <summary>
        /// URI资源
        /// </summary>
        public static int _csuristem { get; set; } = 1;
        /// <summary>
        /// URI查询
        /// </summary>
        public static int _csuriquery { get; set; } = 1;
        /// <summary>
        /// 服务器端口号
        /// </summary>
        public static int _sport { get; set; } = 0;
        /// <summary>
        /// 用户名
        /// </summary>
        public static int _csusername { get; set; } = 0;
        /// <summary>
        /// 客户端IP
        /// </summary>
        public static int _cip { get; set; } = 1;
        /// <summary>
        /// 协议版本
        /// </summary>
        public static int _csversion { get; set; } = 0;
        /// <summary>
        /// 用户代理
        /// </summary>
        public static int _csuseragent { get; set; } = 0;
        /// <summary>
        /// 引用网站
        /// </summary>
        public static int _csreferer { get; set; } = 0;
        /// <summary>
        /// 主机
        /// </summary>
        public static int _cshost { get; set; } = 1;
        /// <summary>
        /// 协议状态
        /// </summary>
        public static int _scstatus { get; set; } = 0;
        /// <summary>
        /// 协议子状态
        /// </summary>
        public static int _scsubstatus { get; set; } = 0;
        /// <summary>
        /// Win32状态
        /// </summary>
        public static int _scwin32status { get; set; } = 0;
        /// <summary>
        /// 发送字节数
        /// </summary>
        public static int _scbytes { get; set; } = 1;
        /// <summary>
        /// 接收字节数
        /// </summary>
        public static int _csbytes { get; set; } = 1;
        /// <summary>
        /// [耗时（ms）]
        /// </summary>
        public static int _timetaken { get; set; } = 1;
        /// <summary>
        /// Cookie
        /// </summary>
        public static int _cscookie { get; set; } = 0;
        /// <summary>
        /// 分析时间
        /// </summary>
        public static int _add_time { get; set; } = 1;


    }
}
